const service = require('../request').service;
const model = require("../../utils/modelUtil");

/**
 * 挖宝
 */

class PreciousDeposits {
    constructor(user) {
        this.user = user;
    }

    //{"error":0,"p":"User.UseDebris","resultCode":200,"User.UseDebris":{"eRet":1,"groupID":4,"needItem":[4203,3],"placeArr":"2938,4,3112,198"},"packetRed":{"packetRedState":0,"packetActivityAward":false},"achievement":{"red":false,"achieveRateId":37}}
    useTuBao(groupID) {
        return new Promise((resolve, reject) => {
            service({
                method: 'POST',
                url: this.user.game.reqUrl + '/UseDebris',
                data: model.userModel('UseDebris', {groupID: groupID}, this.user.game.isWeb, this.user.game.data),
            }).then(res => {
                const resData = res.data;
                resolve(resData.code===200?resData.MsgData:{});
            }).catch(err => {
                reject(err);
            })
        })
    }

    //{"error":0,"p":"User.Storehouse","resultCode":200,"User.Storehouse":{"eRet":1,"rewardArray":{"1":2,"6877":1},"note":{"ivch":{"4185":33,"4186":46,"4187":40,"4188":34,"4189":32,"4190":24,"4191":67,"4192":64,"4193":71,"4194":67,"4203":102,"6877":1},"eco":{"gold":1262},"eqch":{}},"groupID":4,"needItem":[4203,3]},"packetRed":{"packetRedState":2,"packetActivityAward":false},"achievement":{"red":false,"achieveRateId":37}}
    dig(groupID) {
        return new Promise((resolve, reject) => {
            service({
                method: 'POST',
                url: this.user.game.reqUrl + '/Storehouse',
                data: model.userModel('Storehouse', {groupID: groupID, flag: 1}, this.user.game.isWeb, this.user.game.data),
            }).then(res => {
                const resData = res.data;
                resolve(resData.code===200?resData.MsgData:{});
            }).catch(err => {
                reject(err);
            })
        })
    }
}

module.exports = PreciousDeposits;